package com.funny.learning.english.activity;

import java.io.File;
import java.util.ArrayList;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.Toast;

import com.funny.learning.english.BaseActivity;
import com.funny.learning.english.R;
import com.funny.learning.english.api.BaseAjaxCallBack.IAjaxCallbackMMK;
import com.funny.learning.english.api.TiengAnhApi;
import com.funny.learning.english.model.CourseEntity;
import com.funny.learning.english.model.LanguageEntity;

public class TestActvity extends BaseActivity {

	private String[] fileM = {"54cc409d78a23c034475902d.mp3","54cc40b478a23c094a75902a.mp3","54cc40c678a23c044475902d.mp3","54cc40e678a23c034475902e.mp3","54cc412978a23c094a75902b.mp3","54cc409d78a23c034475902d.mp3","54cc409d78a23c034475902d.mp3"};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_test);

		// TiengAnhApi.getLanguageList(this, mAjaxCallbackMMK);

		// TiengAnhApi.getLanguageList(this, mAjaxCallbackMMK);

		// TiengAnhApi.registerLanguage("en", appication.getUserEntity(), this,
		// mAjaxCallbackMMK2);

		// TiengAnhApi.getCourseList(this,appication.getUserEntity(), "en",
		// mAjaxCallbackMMK3);

		// name: "Học tiếng anh cơ bản",
		// url: "54bf86e678a23c07518b4567.jpg",
		// id: "547edc8178a23c373037f8e8"

//		int[] levels = new int[1];
//		levels[0] = 1;

//		TiengAnhApi.playGame(this, mAjaxCallbackMMK4);

		// Đăng ký ngôn ngữ
		// TiengAnhApi.registerLanguage("ja", appication.getUserEntity(), this,
		// mAjaxCallbackMMK2);

		// Danh sách các khóa học theo ngôn ngữ
		// TiengAnhApi.getCourseList(this,appication.getUserEntity(), "en",
		// mAjaxCallbackMMK3);
		
		File fileMDir = new File(this.getFilesDir(), "m");
		File fileIDir = new File(this.getFilesDir(), "i");
		if(!fileMDir.exists()){
			fileMDir.mkdir();
		}
		if(!fileIDir.exists()){
			fileIDir.mkdir();
		}
		ProgressDialog mProgressDialog = new ProgressDialog(activity);
		mProgressDialog.setCanceledOnTouchOutside(false);
		mProgressDialog.setCancelable(true);
		// mProgressDialog.setOnCancelListener(new OnCancelListener() {
		//
		// @Override
		// public void onCancel(DialogInterface dialog) {
		// mAjaxCallbackMMK.onBackDialog();
		//
		// }
		// });
		mProgressDialog.setMessage("Đang tải...");
		mProgressDialog.show();
		
		for (int i = 0; i < fileM.length; i++) {
			TiengAnhApi.downloadData(activity, fileM[i], "tuan" + i);
		}
		
		mProgressDialog.dismiss();

	}

	private IAjaxCallbackMMK mAjaxCallbackMMK4 = new IAjaxCallbackMMK() {

		@Override
		public <T> void handler(T t, int code) {
			// TODO Auto-generated method stub
			if (code == COMPLETE) {

				Toast.makeText(TestActvity.this, "OKKKKKKKKKKKKK", 2000).show();
			} else if (code == ERROR) {
				Toast.makeText(TestActvity.this, "ERRR", 2000).show();
			}
		}
	};

	private IAjaxCallbackMMK mAjaxCallbackMMK3 = new IAjaxCallbackMMK() {

		@Override
		public <T> void handler(T t, int code) {
			// TODO Auto-generated method stub
			if (code == COMPLETE) {
				ArrayList<CourseEntity> courseEntitys = (ArrayList<CourseEntity>) t;
				Toast.makeText(TestActvity.this, courseEntitys.size() + "",
						2000).show();
			} else if (code == ERROR) {
			}
		}
	};

	private IAjaxCallbackMMK mAjaxCallbackMMK2 = new IAjaxCallbackMMK() {

		@Override
		public <T> void handler(T t, int code) {
			// TODO Auto-generated method stub
			if (code == COMPLETE) {

				Toast.makeText(TestActvity.this, "OK", 2000).show();
			} else if (code == ERROR) {
				Toast.makeText(TestActvity.this, (String) t, 2000).show();
			}
		}
	};

	private IAjaxCallbackMMK mAjaxCallbackMMK = new IAjaxCallbackMMK() {

		@Override
		public <T> void handler(T t, int code) {
			// TODO Auto-generated method stub
			if (code == COMPLETE) {
				ArrayList<LanguageEntity> languageEntities = (ArrayList<LanguageEntity>) t;

				Toast.makeText(TestActvity.this, languageEntities.size() + "",
						2000).show();
			} else if (code == ERROR) {

			}
		}
	};

}
